{cp866}
Uses routine,Process,DispProc;
var
d:PDispatcherProcess;
p:TProcess;
procedure proc_i;far;
begin
	while true do
		begin
			d^.get_current_process(p);
			writeln('pid:', p.get_id);
		end;

end;
procedure proc_last;far;
var
	p:TProcess;
	s:string;
	count:byte;
begin
	count:=0;
	while true do
	begin
			{writeln('pid:', p.get_id);}
			if (count = 0) then
				begin
					inc(count);
					d^.lock;
					readln(s);
					writeln(s);
					d^.unlock;		
				end;
			if isEscape then
				d^.stop;
	end;
end;
var
	
	i:word;
	a:array[1..255] of body_process;
	T:TProcess;
	nProcess:	word;
	Main:		descptr;
	beforeMem,
	afterMem:	longint;
begin
	beforeMem:=MemAvail;
	new(Main);
	writeln('enter the a number of process');
	readln(nProcess);
	for i:=1 to nProcess - 1 do a[i]:=proc_i;
	a[nProcess]:=proc_last;
	d:=new(PDispatcherProcess,init(nProcess, a, Main));
	set_current_dispatcher(d);
	d:=get_current_dispatcher;
	d^.start;
	afterMem:=MemAvail;
	writeln('size of Memory before initialize: ', beforeMem);
	writeln('size of Memory before done: ', afterMem);
	d^.done;
	dispose(d);
	dispose(Main);
	writeln('size of Memory after done: ', MemAvail);	
end.
